package smcms.commons.api.entity.util;

import io.jsonwebtoken.Claims;
import io.jsonwebtoken.Jwts;
import io.jsonwebtoken.SignatureAlgorithm;

import java.util.Date;
import java.util.Map;

public class JwtUtil {
    private Long expire = 1000*60*60*24l;

    private String secret = "chsdkch%$(*";
    private final static Long EXPIRE_TIME = System.currentTimeMillis();

    public String generateToken(Map<String, Object> msg){
        String token = Jwts.builder()
                .addClaims(msg)
                .setIssuedAt(new Date(System.currentTimeMillis()))
                .setExpiration(new Date(System.currentTimeMillis()+expire))
                .signWith(SignatureAlgorithm.HS256, secret)
                .compact();
        return token;
    }

    public Claims parseToken(String token) {
        Claims claims = Jwts.parser().setSigningKey(secret).parseClaimsJws(token).getBody();
        return claims;
    }


}